﻿<Window x:Class="AvalonDock.MVVMTestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:avalonDock="http://avalondock.codeplex.com"
        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=AvalonDock"
        xmlns:local="clr-namespace:AvalonDock.MVVMTestApp"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:sysWindows="clr-namespace:System.Windows;assembly=PresentationCore"
        x:Name="mainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:ActiveDocumentConverter x:Key="ActiveDocumentConverter"/>
        <avalonDock:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem Header="File">
                <MenuItem Header="New" Command="{Binding NewCommand}"/>
                <MenuItem Header="Open" Command="{Binding OpenCommand}"/>
                <Separator/>
                <MenuItem Header="Save" Command="{Binding ActiveDocument.SaveCommand}"/>
                <MenuItem Header="Save As..." Command="{Binding ActiveDocument.SaveAsCommand}"/>
                <Separator/>
                <MenuItem Header="Close" Command="{Binding ActiveDocument.CloseCommand}"/>
            </MenuItem>
            <MenuItem Header="Tools">
                <MenuItem Header="Properties" IsChecked="{Binding FileStats.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
            </MenuItem>
            <MenuItem Header="Layout">
                <MenuItem Header="Load" Command="{Binding LoadLayoutCommand, ElementName=mainWindow}"/>
                <MenuItem Header="Save" Command="{Binding SaveLayoutCommand, ElementName=mainWindow}"/>
            </MenuItem>
        </Menu><!--AnchorablesSource="{Binding Tools}" DocumentsSource="{Binding Files}"-->
        <avalonDock:DockingManager x:Name="dockManager" AllowMixedOrientation="True"
                                   AnchorablesSource="{Binding Tools}" 
                                   DocumentsSource="{Binding Files}"
                                   ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
                                   Grid.Row="1">

            <avalonDock:DockingManager.LayoutItemTemplateSelector>
                <local:PanesTemplateSelector>
                    <local:PanesTemplateSelector.FileViewTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding TextContent, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </local:PanesTemplateSelector.FileViewTemplate>
                    <local:PanesTemplateSelector.FileStatsViewTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="{Binding FileSize}"/>
                                <TextBlock Text="{Binding LastModified}"/>
                            </StackPanel>
                        </DataTemplate>
                    </local:PanesTemplateSelector.FileStatsViewTemplate>
                </local:PanesTemplateSelector>
            </avalonDock:DockingManager.LayoutItemTemplateSelector>
            
            <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
                <local:PanesStyleSelector>
                    <local:PanesStyleSelector.ToolStyle>
                        <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                            <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                            <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                            <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                            <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                        </Style>
                    </local:PanesStyleSelector.ToolStyle>
                    <local:PanesStyleSelector.FileStyle>
                        <Style TargetType="{x:Type avalonDock:LayoutItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                            <Setter Property="ToolTip" Value="{Binding Model.FilePath}"/>
                            <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
                            <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                        </Style>
                    </local:PanesStyleSelector.FileStyle>
                </local:PanesStyleSelector>
            </avalonDock:DockingManager.LayoutItemContainerStyleSelector>
            <avalonDock:DockingManager.LayoutUpdateStrategy>
                <local:LayoutInitializer/>
            </avalonDock:DockingManager.LayoutUpdateStrategy>
            
            <avalonDock:LayoutRoot>
                <avalonDock:LayoutPanel Orientation="Vertical">
                    <avalonDock:LayoutDocumentPane/>
                    <avalonDock:LayoutAnchorablePane Name="ToolsPane" DockHeight="150">
                    </avalonDock:LayoutAnchorablePane>
                </avalonDock:LayoutPanel>
            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>
    </Grid>
</Window>
